package org.example.c1;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author liu-rui
 * @date 2020/5/27 上午10:56
 * @description 演示守护线程
 * @since
 */
@Slf4j
public class Demo7 {
    public static void main(String[] args) throws InterruptedException {
        final Thread t = new Thread(() -> {
            new Thread(() -> {
                for (int i = 0; ; i++) {
                    log.info("{}", i);
                }
            }, "t2").start();

            for (int i = 0; ; i++) {
                log.info("{}", i);
            }
        }, "t1");
        t.setDaemon(true); //演示开关；演示所有用户线程退出后，进程结束
        t.start();

        //主线程休息２秒后退出
        TimeUnit.SECONDS.sleep(2);
    }
}
